package grape.crm.rest.customertag.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.crm.rest.customertag.form.CustomerTagCreateForm;
import grape.crm.rest.customertag.form.CustomerTagUpdateForm;
import grape.crm.rest.customertag.form.CustomerTagListPageForm;
import grape.crm.rest.customertag.vo.CustomerTagVo;
import grape.crm.rest.customertag.mapper.CustomerTagWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.crm.service.customertag.po.CustomerTag;
import grape.crm.service.customertag.api.ICustomerTagService;
import java.util.List;
/**
 * <p>
 * 客户标签 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-09-16
 */
@RestController
@RequestMapping("/crm/customertag")
@Api(tags = "客户标签相关接口")
public class CustomerTagController extends BaseController<CustomerTagVo, CustomerTag> {

    @Autowired
    private CustomerTagWebMapper currentWebMapper;
    @Autowired
    private ICustomerTagService currentService;



     @ApiOperation("添加客户标签")
     @PreAuthorize("hasAuthority('customertag:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public CustomerTagVo create(@RequestBody @Valid CustomerTagCreateForm cf) {
         CustomerTag po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询客户标签")
     @PreAuthorize("hasAuthority('customertag:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public CustomerTagVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除客户标签")
     @PreAuthorize("hasAuthority('customertag:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新客户标签")
     @PreAuthorize("hasAuthority('customertag:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public CustomerTagVo update(@PathVariable String id,@RequestBody @Valid CustomerTagUpdateForm uf) {
         CustomerTag po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("分页查询客户标签")
    @PreAuthorize("hasAuthority('customertag:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<CustomerTagVo> listPage(CustomerTagListPageForm listPageForm) {
         CustomerTag po = currentWebMapper.formToPo(listPageForm);
         return super.listPage(po,listPageForm);
     }

}
